package com.nstar.carousel.utils
{
	import flash.display.GradientType;
	import flash.display.Graphics;
	import flash.display.SpreadMethod;
	import flash.filters.BitmapFilter;
	import flash.filters.BitmapFilterQuality;
	import flash.filters.GlowFilter;
	import flash.geom.Matrix;
	
	public class CarouselGraphicsUtils
	{
		public static const HORIZONTAL:String = "horizontal";
		public static const VERTICAL:String = "vertical";
				
		public function CarouselGraphicsUtils()
		{
		}

		//画渐变背景
		public static function drawBackground(g:Graphics,color1:uint,color2:uint,
			width:Number,height:Number,direction:String=VERTICAL):void{
			g.lineStyle(1, 0x000000, 0, true); 
            var matr:Matrix = new Matrix();
            
            var r:Number = direction==HORIZONTAL?0:Math.PI/2;
            
  			matr.createGradientBox(width-2, height-2, r, 0, 0);
  			var spreadMethod:String = SpreadMethod.PAD;
            g.beginGradientFill( GradientType.LINEAR,[color1,color2],[1,1],[0,255],matr,spreadMethod);

            g.drawRect(1, 1, width-1, height - 1);   
		}
		
        public static function getBitmapFilter(color:Number = 0xffffff,blur:Number=8):BitmapFilter {
            var alpha:Number = 0.8;
            var blurX:Number = blur;
            var blurY:Number = blur;
            var strength:Number = 2;
            var inner:Boolean = false;
            var knockout:Boolean = false;
            var quality:Number = BitmapFilterQuality.HIGH;
            return new GlowFilter(color,
                                  alpha,
                                  blurX,
                                  blurY,
                                  strength,
                                  quality,
                                  inner,
                                  knockout);
        }	
        
        //返回发光过滤器
        public static function setFlowEffect(object:Object,color:Number = 0xffffff,blur:Number=8):void{
        	var filter:BitmapFilter = getBitmapFilter(color,blur);
        	var myFilters:Array = new Array();
        	myFilters.push(filter);
        	object.filters = myFilters;
        }		
	}
}